package com.smartshopping.view;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.smartshopping.model.*;

public class ListMarketAdapter extends ArrayAdapter<Market>{
	ArrayList<Market> array;
    int resource;
    Context context;
    
    public ListMarketAdapter(Context context, int textViewResourceId, ArrayList<Market> objects) {
        super(context, textViewResourceId, objects);
        this.array = objects;
        this.resource = textViewResourceId;
        this.context = context;
    }
    
    //Always have the getView function for the Adapter
    @Override
	public View getView(int position, View convertView, ViewGroup parent){
        View marketItemView = convertView;
        //Get context
        if(marketItemView == null){
            marketItemView = new ListMarketItem(context);
        }
        final Market market = array.get(position);
        //Set the parameter for each layout in each element in list
        if(market!=null){
        	((ListMarketItem)marketItemView).setImage(market.getUrl());
        	((ListMarketItem)marketItemView).setName(market.getName());
        	((ListMarketItem)marketItemView).setPhone("Phone: " + market.getPhone());
        	((ListMarketItem)marketItemView).setAddress(market.getAddress());
        }
        return marketItemView;
    }
}
